package com.minelx.scriptbuilder.script.attribute.function;

import com.minelx.scriptbuilder.script.IVariable;
import com.minelx.scriptbuilder.script.attribute.value.IAttribute;
import com.minelx.scriptbuilder.script.attribute.value.IntValue;

import static java.lang.String.valueOf;

public class SumFunction implements Function {

	@Override
	public IAttribute execute(Params params) {
		return new IntValue(Integer.parseInt(valueOf(
				params.values().stream()
						.map(IVariable::value)
						.map(IAttribute::asString).map(Integer::parseInt)
						.reduce(0, Integer::sum))));
	}
}
